package com.link.cloud.page;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 分页数据通用对象
 * 
 */
public class Paging<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    // 总记录数
    private long total = 0;
    // 总页数
    private int pages = 0;
    // 当前页,从1开始
    private int pageNum = 1;
    // 每页的数量
    private int pageSize = 10;
    // 当前页的数量
    private int size = 0;
    // 排序
    private String orderBy;
    // 结果集
    private List<T> items;

    public Paging() {

        this(new ArrayList<>());
    }

    public Paging(List<T> list) {

        if (list == null || list.isEmpty()) {
            return;
        }

        // mybatis的自定义分页类型
        if (list instanceof com.github.pagehelper.Page) {
            com.github.pagehelper.Page page = (com.github.pagehelper.Page) list;
            this.pageNum = page.getPageNum();
            this.pageSize = page.getPageSize();
            this.orderBy = page.getOrderBy();

            this.pages = page.getPages();
            this.items = page;
            this.size = page.size();
            this.total = page.getTotal();
        } else {
            this.pageNum = 1;
            this.pageSize = list.size();

            this.pages = 1;
            this.items = list;
            this.size = list.size();
            this.total = list.size();
        }
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPages() {
        return pages;
    }

    public void setPages(int pages) {
        this.pages = pages;
    }

    public List<T> getItems() {
        return items;
    }

    public void setItems(List<T> items) {
        this.items = items;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

}

